package com.darsn.fowtle.core.repository.hibernate;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.darsn.fowtle.core.common.Guard;
import com.darsn.fowtle.core.domain.User;
import com.darsn.fowtle.core.repository.UserRepository;

@Repository
public class HibernateUserRepository extends AbstractHibernateRepository implements UserRepository {

	@Override
	public User findUser(String username, String password) throws IllegalArgumentException {
		Guard.assertNotNull(username, "username");
		Guard.assertNotBlank(username, "username");
		Guard.assertNotNull(password, "password");
		Guard.assertNotBlank(password, "password");

		Query query = getSession().createQuery("from User where username=:username and password=:password");
		query.setString("username", username);
		query.setString("password", password);
		
		return (User)query.uniqueResult();
	}

}
